package www.m01.springcloud.swagger;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * SwaggerConfig
 *
 * @author hyr
 * @date 2022/7/11
 */
@Configuration
@EnableOpenApi
@EnableKnife4j
public class SwaggerConfig {

    @Value("${swagger.enabled:false}")
    Boolean swaggerEnabled;

    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.OAS_30)
            .apiInfo(apiInfo())
            // 是否开启swagger
            .enable(swaggerEnabled)
            .select()
            // 过滤条件，扫描指定路径下的文件
            .apis(RequestHandlerSelectors.basePackage("www.m01.springcloud.controller"))
            // 指定路径处理，PathSelectors.any()代表不过滤任何路径
            //.paths(PathSelectors.any())
            .build();
    }

    private ApiInfo apiInfo() {
        /*作者信息*/
        Contact contact = new Contact("m01", "", "");
        return new ApiInfo(
            "Spring Boot 集成 Swagger3 测试",
            "Spring Boot 集成 Swagger3 测试接口文档",
            "v1.0",
            "",
            contact,
            "Apache 2.0",
            "http://www.apache.org/licenses/LICENSE-2.0",
            new ArrayList()
        );
    }
}
